<template>
	<view :style="themeColor">
		<view class="page">
			<view class="flex benben-position-layout flex flex-wrap align-center user_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between flex-sub user_fd0_0'>
					<view class='flex flex-wrap align-center' @tap.stop="handleJumpDiy" data-type="back" data-url="1">
						<text class='fu-iconfont2  user_fd0_0_c0_c0' @tap.stop="handleJumpDiy" data-type="back"
							data-url="1">&#xE794;</text>
					</view>
					<view class='flex flex-wrap align-stretch justify-center flex-sub'>
						<text class='user_fd0_0_c1_c0'>上传信息</text>
					</view>
					<view class='flex flex-wrap align-center user_fd0_0_c2'>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			<!---白哦但flex布局开始-->
			<view class="flex flex-direction flex-wrap align-stretch user_flex_1" v-if="isTupian">
				<view class='flex flex-wrap align-center justify-between user_fd1_0' v-if="isadd">
					<text class='user_fd1_0_c0'>上传照片</text>
					<view class="upload position-relative">
						<image class=" user_fd1_0_c1_image" mode="aspectFill" :src="info.ossUrl"></image>
					</view>
				</view>
				<view class='flex flex-wrap align-center justify-between user_fd1_0' v-else>
					<text class='user_fd1_0_c0'>上传照片</text>
					<view class="upload position-relative">
						<image class=" user_fd1_0_c1_image" mode="aspectFill"
							@tap="croppingUploadImage('ossUrl','ossUrl',info,info)"
							:src="info.ossUrl ? info.ossUrl : require('@/static/images/129.png')"></image>
					</view>
				</view>
				<view class='flex flex-wrap align-center justify-between user_fd1_0' v-if="isOnlines==1">
					<text class='user_fd1_2_c01'>1.人脸大小适中人头占整个图片1/3-1/2之间为宜。</text>
					<text class='user_fd1_2_c01'>2.正对相机.人头在正中间，人头左右上下，均正对摄像头</text>
					<text class='user_fd1_2_c01'>3.光线均匀，禁止过暗或过曝，禁止过度化妆及使用美颜相机</text>
					<text class='user_fd1_2_c01'>4.脸部不能遮挡并确保图片清晰，正常表情，不能有搞怪动作</text>
					<text class='user_fd1_2_c01'>5.禁止在夜间及逆光下取图，人与背景光线要均匀</text>

				</view>


				<view class='flex flex-wrap align-center justify-between user_fd1_0'>
					<text class='user_fd1_2_c0'>姓名</text>
					<input class='flex-sub user_fd1_1_c1' type="text" :placeholder="'请输入'" confirm-type="done" :maxlength="7"
						placeholder-style="color:rgba(102, 102, 102, 1);font-size:32rpx" v-model="info.memberName" />
				</view>
				<view class='flex flex-wrap align-center justify-between user_fd1_0' @tap.stop="pickerDiy1683966462102=true">
					<!--  -->
					<text class='user_fd1_2_c0'>性别</text>
					<input class='flex-sub user_fd1_1_c1' type="text" confirm-type="done" :maxlength="30"
						placeholder-style="color:rgba(102, 102, 102, 1);font-size:32rpx" v-model="sex_label" :disabled="true" />
					<text class='fu-iconfont2  user_fd1_3_c2'>&#xE78E;</text>
				</view>
				<view class='flex flex-wrap align-center justify-between user_fd1_0'>
					<text class='user_fd1_2_c0'>联系方式</text>
					<input class='flex-sub user_fd1_1_c1' type="number" confirm-type="done" :maxlength="11"
						placeholder-style="color:rgba(102, 102, 102, 1);font-size:32rpx" :placeholder="'请输入'"
						v-model="info.phoneNumber" disabled="true" />
				</view>

			</view>

			<!--选择日期结束 -->
			<view class="flex flex-direction align-center benben-position-layout flex user_flex_4">
				<button class='user_fd4_0' @tap.stop="setUserInfoFunc()">保存</button>
			</view>
			<benben-picker ref="benbenWritePickerCodepicker2" :visible.sync="pickerDiy1683966462102" :label.sync='sex_label'
				:value.sync='sex_value' :options='sex_options' mode='selector' :mask-show='true' :timeout='true'
				:picker-height='88' default-type='value' :default-props='{"label":"name","value":"value"}'>
				<template #picker-header>
					<view class='flex flex-wrap align-center justify-between user_picker2_0'>
						<text class='user_picker2_0_c0' @tap="$refs.benbenWritePickerCodepicker2.cancel()">取消</text>
						<text class='user_picker2_0_c1'>选择性别</text>
						<text class='user_picker2_0_c2' @tap="$refs.benbenWritePickerCodepicker2.pickerConfirm()">确定</text>
					</view>
				</template>
			</benben-picker>
			<view :style="{height: '130rpx'}"></view>


		</view>
	</view>
</template>
<script>
	import UploadImage from '@/common/utils/upload-image.js'

	import {
		validate
	} from '@/common/utils/validate.js'
	export default {
		components: {},


		data() {
			return {
				info: {
					ossUrl: '',
					ossId: '',
					memberName: '',
					memberSex: '',
					birthday: '',
					phoneNumber: '',
				},
				imginfo: {
					ossUrl: '',
					ossId: ''
				},
				"pickerDiy1684137696643": false,
				"pickerDiy1683966462102": false,
				"fd1_0_c1id": "",
				ishsow: false,
				isTupian: false,
				isOnlines: '',
				isadd: false,
				"sex_options": [{
					"name": "男",
					"value": "1",
					"image": ""
				}, {
					"name": "女",
					"value": "2",
					"image": ""
				}, {
					"name": "保密",
					"value": "3",
					"image": ""
				}],
				"sex_value": "",
				"sex_label": ""
			};
		},
		computed: {

			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			this.Online()
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {
			setTimeout(() => {
				this.queryUserInfoFunc()
			}, 200)
		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			//裁剪图片上传
			croppingUploadImage(id, path, obj, obj1, fnName = false) {
				let self = this
				if (!obj) obj = this
				if (!obj1) obj1 = this
				let itemList = obj1[path] ? ['修改', '拍照', '从手机相册选择'] : ['拍照', '从手机相册选择']

				function imageCroppingCuccess() {
					uni.$once('image-cropping-success', (file) => {
						console.log(file, '裁剪之后的图片参数')
						if (!file) return
						new UploadImage([file], {
							complete: (res) => {
								if (id) self.$set(obj, id, res[0].id)
								if (path) self.$set(obj1, path, res[0].path)
								if (fnName) self[fnName]()
							},
						})
					})
				}
				uni.showActionSheet({
					itemList: itemList,
					success: function(res) {
						if (res.tapIndex == 0 && obj1[path]) {
							console.log('修改头像')
							uni.navigateTo({
								url: '/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&&myImgUrl=' +
									obj1[path],
								animationDuration: 0,
							})
							imageCroppingCuccess()
						}
						if ((res.tapIndex == 1 && obj1[path]) || (res.tapIndex == 0 && !obj1[path])) {
							console.log('拍照')
							uni.chooseImage({
								count: 1,
								sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
								sourceType: ['camera'], // 可以指定来源是相册还是相机，默认二者都有
								success: (res) => {
									console.log(res, '图片chooseImage上传参数')
									// 跳转到图片裁切页面
									uni.navigateTo({
										url: `/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&fileType=${res.tempFiles[0].type}&myImgUrl=${res.tempFilePaths[0]}`,
										animationDuration: 0,
									})
									imageCroppingCuccess()
								},
							})
						}
						if ((res.tapIndex == 2 && obj1[path]) || (res.tapIndex == 1 && !obj1[path])) {
							uni.chooseImage({
								count: 1,
								sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图，默认二者都有
								sourceType: ['album'], // 可以指定来源是相册还是相机，默认二者都有
								success: (res) => {
									// 跳转到图片裁切页面
									uni.navigateTo({
										url: `/pages/benben-built-in/image-cropping/image-cropping?rectHeight=200&rectWidth=200&fileType=${res.tempFiles[0].type}&myImgUrl=${res.tempFilePaths[0]}`,
										animationDuration: 0,
									})
									imageCroppingCuccess()
								},
							})
						}
					},
					fail: function(res) {
						console.log(res.errMsg)
					},
				})
			},

			//获取用户详细信息
			async queryUserInfoFunc() {
				//请求方法
				//数据验证
				uni.showLoading({
					title: '加载中',
					mask: false
				});
				let id = uni.getStorageSync('userId')
				let requestUrl = `${global.apiUrls.memberInfo}/${id}`;
				let datauserInfo = await this.$api.get(requestUrl);
				if (datauserInfo.data.code != 200) {
					this.$message.info(datauserInfo.data.msg);
					uni.hideLoading()
					return
				} else {
					this.info = datauserInfo.data.data
					if (this.info.ossUrl) {
						this.isadd = true
					}
					if (this.info.memberSex == 1) {
						this.sex_label = '男'
					} else if (this.info.memberSex == 0) {
						this.sex_label = '女'
					} else {
						this.sex_label = '保密'
					}
					uni.hideLoading()
				}


				console.log(this.info, '用户信息')
				if (uni.getStorageSync('IMGINFO')) {
					this.imginfo = uni.getStorageSync('IMGINFO')
					this.info.ossUrl = this.imginfo.url
					this.isadd = false
					console.log(this.info.ossUrl, '进来了--图片信息')
				}
				uni.hideLoading()
				this.isTupian=true
			},
			async Online() {
				//请求方法
				let datauserInfo = await this.$api.get(global.apiUrls.isOnline);
				this.isOnlines = datauserInfo.data.data
				console.log(this.isOnlines, 'isOnlinesisOnlinesisOnlines')
			},
			//修改用户资料
			async setUserInfoFunc() {
				if (this.sex_label == '男') {
					this.info.memberSex = 1
				} else if (this.sex_label == '女') {
					this.info.memberSex = 0
				} else if (this.sex_label == '保密') {
					this.info.memberSex = 2
				}
				//请求方法
				//数据验证
				let id = uni.getStorageSync('userId')
				let datauser = await this.$api.put(global.apiUrls.changeInfo, {
					ossId: this.imginfo.ossId ? this.imginfo.ossId : this.info.ossId,
					ossUrl: this.imginfo.url ? this.imginfo.url : this.info.url,
					memberName: this.info.memberName,
					phoneNumber: this.info.phoneNumber,
					memberSex: this.info.memberSex,
					id: id
				});

				if (datauser.data.code != 200) {
					this.$message.info(datauser.data.msg);
					return
				}
				uni.removeStorageSync('IMGINFO')
				this.$message.info('保存成功');
				this.queryUserInfoFunc()
				setTimeout(() => {
					uni.navigateBack(1)
				}, 800)

			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: rgba(255, 255, 255, 1);
		background-size: 100% auto;
	}

	.user_flex_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.user_fd0_0_c2 {
		width: 32rpx;
		height: 32rpx;
	}

	.user_fd0_0_c1_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333;
	}

	.user_fd0_0_c0_c0 {
		font-size: 32rpx;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
		line-height: 88rpx;
	}

	.user_fd0_0 {
		margin: 0rpx 32rpx 0rpx 32rpx;
	}

	.user_flex_1 {
		background: #fff;
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.user_fd1_3_c2 {
		font-size: 28rpx;
		margin: 0rpx 0rpx 0rpx 14rpx;
	}

	.user_fd1_2_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: rgba(102, 102, 102, 1);
		max-width: 400rpx;
		-webkit-line-clamp: 1;
		overflow: hidden;
		text-overflow: ellipsis;
		display: -webkit-box;
		-webkit-box-orient: vertical;
	}

	.user_fd1_2_c0 {
		font-size: 32rpx;
		font-weight: 400;
		color: rgba(51, 51, 51, 1);
	}

	.user_fd1_2_c01 {
		font-size: 28rpx;
		font-weight: 400;
		color: #999;
		margin-bottom: 4rpx;
	}

	.user_fd1_1_c1 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		text-align: right;
		margin: 0rpx 0rpx 0rpx 48rpx;
	}

	.user_fd1_0_c1_image {
		width: 100rpx;
		height: 100rpx;
		border-radius: 50rpx 50rpx 50rpx 50rpx;
	}

	.user_fd1_0_c0 {
		font-size: 32rpx;
		font-weight: 400;
		color: var(--benbenFontColor0);
	}

	.user_fd1_0 {
		border-bottom: 1px solid #eee;
		padding: 24rpx 0rpx 24rpx 0rpx;
	}

	.user_picker2_0_c2 {
		color: var(--benbenFontColor0);
		font-size: 32rpx;
		font-weight: 400;
	}

	.user_picker2_0_c1 {
		color: var(--benbenFontColor0);
		font-size: 32rpx;
		font-weight: 500;
	}

	.user_picker2_0_c0 {
		color: rgba(153, 153, 153, 1);
		font-size: 32rpx;
		font-weight: 400;
	}

	.user_picker2_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		padding: 0rpx 32rpx 0rpx 32rpx;
		line-height: 88rpx;
		border-radius: 25rpx 25rpx 0rpx 0rpx;
		background-size: 100% auto !important;
	}

	.user_picker3_0_c2 {
		color: var(--benbenFontColor0);
		font-size: 32rpx;
		font-weight: 400;
	}

	.user_picker3_0_c1 {
		color: var(--benbenFontColor0);
		font-size: 32rpx;
		font-weight: 500;
	}

	.user_picker3_0_c0 {
		color: rgba(153, 153, 153, 1);
		font-size: 32rpx;
		font-weight: 400;
	}

	.user_picker3_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		padding: 0rpx 32rpx 0rpx 32rpx;
		line-height: 88rpx;
		border-radius: 25rpx 25rpx 0rpx 0rpx;
		background-size: 100% auto !important;
	}

	.user_flex_4 {
		width: 750rpx;
		height: 130rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
	}

	.user_fd4_0 {
		background: #167deb;
		border-radius: 180rpx 180rpx 180rpx 180rpx;
		font-size: 32rpx;
		color: rgba(255, 255, 255, 1);
		height: 88rpx;
		line-height: 88rpx;
		width: 640rpx;
		font-weight: 500;
	}
</style>